#encoding: utf-8

import io
import sys
import time

# def main():
# 	f = None
# 	try:
# 		with open('致橡树.txt', 'r', encoding='utf-8') as f:
# 			print(f.read())
# 	except FileNotFoundError:
# 		print('无法打开指定文件')
# 	except LookupError:
# 		print('指定了未知编码')
# 	except UnicodeDecodeError:
# 		print('读取文件时解码错误')
	# finally:
	# 	if f:
	# 		f.close()
	

# def main():
# 	# with open('致橡树.txt', 'r', encoding='utf-8') as f:
# 	# 		print(f.read())

# 	# with open('致橡树.txt', 'r', encoding='utf-8') as f:
# 	# 		for line in f:
# 	# 			print(line, end = '')
# 	# 			time.sleep(0.5)
# 	# 			pass

# 	with open('致橡树.txt') as f:
# 		lines = f.readlines()
# 	print(lines)
# 	pass


from math import sqrt

def is_prime(n):
	assert n > 0
	for factor in range(2, int(sqrt(n)) + 1):
		if n % factor == 0:
			return False
	return True if n != 1 else False

#写文件
# def main():
# 	filenames = ('a.txt', 'b.txt')
# 	fs_list = []

# 	try:
# 		for filename in filenames:
# 			fs_list.append(open(filename , 'w', encoding='utf-8'))
# 		for number in range(1, 1000):
# 			if is_prime(number):
# 				if number<100:
# 					fs_list[0].write(str(number) + '\n')
# 				else:
# 					fs_list[1].write(str(number) + '\n')

# 	except IOError as ex:
# 		print(ex)
# 		print('写文件时发生错误')
# 	finally:
# 		for fs in fs_list:
# 			fs.close()

import requests
import json

def main():
	resp = requests.get('http://api.tianapi.com/guonei/?key=APIKey&num=10')
	data_model = json.loads(resp.text)
	print(data_model)
	for news in data_model['msg']:
		print(news[0])
		pass
	pass

# def main():
# 	mydict = {
# 		'name' : 'X小小',
# 		'age':38,
# 		'qq':3710549,
# 		'friends' : ['王大锤', '元芳'],
# 		'cars' : [
# 			{'brand' : 'byd' , 'max_speed': 180},
# 			{'brand' : 'audi', 'max_speed': 280},
# 		]  
# 	}

# 	try:
# 		with open('data.json', 'w', encoding='utf-8') as fs:
# 			json.dump(mydict, fs)
# 	except IOError as e:
# 		print(e)
# 	print('保存数据完成')


if __name__ == '__main__':
	main()













